package com.cloud.system.api.provider;

import com.cloud.system.api.bean.RecCheckUnitCriteriaBean;
import com.cloud.system.api.bean.RecPunishSuperviseItemCriteriaBean;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.jdbc.SQL;

public class SuperviseBeanPageProvider {

    public String searchCheckItem(RecCheckUnitCriteriaBean bean) {
        String LIST_PAGE_SELECT = "t1.sup_code, t1.sup_name, t1.permit_name,t1.sup_sub_item,t1.sup_id, t2.sup_item_code, t2.inspect_execute_list_code",
                LIST_PAGE_FOMR = " unit_supervise t1, unit_inspect t2";

        SQL sql = new SQL().SELECT(LIST_PAGE_SELECT).FROM(LIST_PAGE_FOMR);

        sql.WHERE("t1.sup_code in (" + String.join(",",bean.getSupCode())+ ")");

        sql.WHERE(" t1.sup_code = t2.sup_item_code");

        if (StringUtils.isNotEmpty(bean.getSupSubItem())) {
            sql.WHERE(" t1.sup_sub_item like '%" + bean.getSupSubItem() + "%'");
        }

        sql.GROUP_BY("t1.sup_code");
        return sql.toString();
    }

    public String searchSuperviseItem(RecPunishSuperviseItemCriteriaBean bean) {
        String LIST_PAGE_SELECT = "sup_code,sup_name, permit_name,sup_sub_item,sup_id",
                LIST_PAGE_FOMR = " unit_supervise";

        SQL sql = new SQL().SELECT(LIST_PAGE_SELECT).FROM(LIST_PAGE_FOMR);

        sql.WHERE("sup_code in (" + String.join(",",bean.getSupCode())+ ")");

        if (StringUtils.isNotEmpty(bean.getSupName())) {
            sql.WHERE(" sup_name like '%" + bean.getSupName() + "%'");
        }

        if (StringUtils.isNotEmpty(bean.getSupSubItem())) {
            sql.WHERE(" sup_sub_item like '%" + bean.getSupSubItem() + "%'");
        }

        sql.GROUP_BY("sup_code");

        sql.ORDER_BY("sup_name asc ,sup_sub_item-0 asc");
        return sql.toString();
    }
}
